<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>DM-CtrlH7-BF-DevProgram: daemon</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="DMBF-Black.png"/></td>
  <td id="projectalign">
   <div id="projectname">DM-CtrlH7-BF-DevProgram<span id="projectnumber">&#160;beta 0.1</span>
   </div>
   <div id="projectbrief">C.ONE Studio Damiao Development Board Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search',true);
  $(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(function(){initNavTree('md_modules_2daemon_2daemon.html','',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">daemon </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="autotoc_md48"></a></p>
<p align="right"></p>
<p><a href="#" onclick="location.href='mai'+'lto:'+'neo'+'zn'+'g1@'+'hn'+'u.e'+'du'+'.cn'; return false;">neozn<span class="obfuscator">.nosp@m.</span>g1@h<span class="obfuscator">.nosp@m.</span>nu.ed<span class="obfuscator">.nosp@m.</span>u.cn</a></p>
<p>用于监测模块和应用运行情况的module(和官方代码中的deteck task作用相同)</p>
<h1 class="doxsection"><a class="anchor" id="autotoc_md49"></a>
使用范例</h1>
<p>要使用该module，则包含<span class="tt"><a class="el" href="daemon_8h_source.html">daemon.h</a></span>的头文件，并在使用daemon的文件中保留一个daemon的指针。</p>
<p>初始化的时候，要传入以下参数：</p>
<div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span></div>
<div class="line">{</div>
<div class="line">    uint16_t reload_count;     <span class="comment">// 实际上这是app唯一需要设置的值?</span></div>
<div class="line">    offline_callback callback; <span class="comment">// 异常处理函数,当模块发生异常时会被调用</span></div>
<div class="line">    <span class="keywordtype">void</span> *owner_id;            <span class="comment">// id取拥有daemon的实例的地址,如DJIMotorInstance*,cast成void*类型</span></div>
<div class="line">} <a class="code hl_struct" href="struct_daemon___init___config__s.html">Daemon_Init_Config_s</a>;</div>
<div class="ttc" id="astruct_daemon___init___config__s_html"><div class="ttname"><a href="struct_daemon___init___config__s.html">Daemon_Init_Config_s</a></div><div class="ttdef"><b>Definition</b> daemon.h:24</div></div>
</div><!-- fragment --><p><span class="tt">reload_count</span>是”喂狗“时的重载值，一般根据你希望的离线容许时间和模块接收数据/访问数据的频率确定。daemonTask递减计数器的频率是100hz(在HAL_N_Middlewares/Src/freertos.c中查看任务),你可以据此以及模块收到数据/操作的频率设置reload_count。</p>
<p><span class="tt">daemon_task()</span>会在实时系统中以1kHz的频率运行，每次运行该任务，都会将所有daemon实例当前的count进行自减操作，当count减为零，则说明模块已经很久没有上线（处于deactivated状态，即没有收到数据，也没有进行其他读写操作）。</p>
<p><span class="tt">offline_callback</span>是模块离线的回调函数，即当包含daemon的模块发生离线情况时，该函数会被调用以应对离线情况，如重启模块，重新初始化等。如果没有则传入<span class="tt">NULL</span>即可。</p>
<p><span class="tt">owner_id</span>即模块取自身地址并通过强制类型转换化为<span class="tt">void*</span>类型，用于拥有多个实例的模块在<span class="tt">offline_callback</span>中区分自身。如多个电机都使用一个相同的<span class="tt">offline_callback</span>，那么在调用回调函数的时候就可以通过该指针来访问某个特定的电机。</p>
<blockquote class="doxtable">
<p>这种方法也称作“parent pointer”，即**保存拥有指向自身的指针对象的地址**。这样就可以在特定的情况下通过自身来访问自己的父对象。 </p>
</blockquote>
<h1 class="doxsection"><a class="anchor" id="autotoc_md50"></a>
具体实现</h1>
<p>即<span class="tt">DaemonTask()</span>，在操作系统中以1kHz运行。注释详细，请参见<span class="tt">daemon.c</span>。 </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div id="page-nav" class="page-nav-panel">
<div id="page-nav-resize-handle"></div>
<div id="page-nav-tree">
<div id="page-nav-contents">
</div><!-- page-nav-contents -->
</div><!-- page-nav-tree -->
</div><!-- page-nav -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
  </ul>
</div>
</body>
</html>
